﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Bpms.Control;
using Bpms.Common;

namespace Bpms.Web.userManagement.user
{
    public partial class userDetail : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["userId"] = Utility.GetQueryInt("userId");

                if ((int)ViewState["userId"] < 1)
                {
                    AlertBack("请正确操作！");
                }

                BindUserDetail((int)ViewState["userId"]);
            }
        }

        /// <summary>
        /// 绑定用户详细信息
        /// </summary>
        /// <param name="userId">用户的UserID</param>
        private void BindUserDetail(int userId)
        {
            Bpms.Entity.UserInfo user = Bpms.Bll.User.GetUser(userId);

            if (null != user)
            {
                lblChName.Text = user.ChName;           // 中文名
                lblEnName.Text = user.EnName;           // 英文名
                lblGender.Text = user.Gender == 2 ? "女" : "男";            // 性别
                lblEmail.Text = user.Email;             // E-mail
                lblTeam.Text = Bpms.Bll.Organization.GetOrganizationName(user.OrganizationID);      // 团队
                lblJobTitle.Text = Bpms.Bll.JobTitle.GetJobTitleName(user.JobTitleID);              // 职位
                lblMobile.Text = user.Mobile;           // 手机
                lblLastLoginTime.Text = user.LastLoginTime.ToString();      // 最后登录时间
                lblLastLoginIP.Text = user.LastLoginIP;                     // 最后登录IP
                lblRoleName.Text = Bpms.Bll.Role.GetRoleName(user.RoleID);  // 角色
                lblIsEnabled.Text = user.IsEnabled == 1 ? "启动" : "注销";
                spanRemark.InnerHtml = user.Remark;     // 备注

                int departmentId = Bpms.Bll.Organization.GetOrganization(user.OrganizationID).OrganizationID;       // 用户所在部门ID
                lblDepartment.Text = Bpms.Bll.Organization.GetOrganization(departmentId).Name;                      // 用户所在部门名称 
            }
        }

        /// <summary>
        /// 绑定角色
        /// </summary>
        public void BindRoleList()
        {
            ddlRole.DataSource = Bpms.Bll.Role.GetRoles();
            ddlRole.DataTextField = "Name";
            ddlRole.DataValueField = "RoleID";
            ddlRole.DataBind();
        }
    }
}
